#Figure 4a

library(foreign)
library(readstata13)
data<-read.dta13("Figure4aData.dta")
counter<-data[,1]
coef<-data[,3]
pdf(file="Figure4a.pdf", family="Bookman")
plot(counter, coef, pch=1, xlim=c(1,10), ylim=c(-.000015, -0.000003), xlab="Percentile Restrictions (i.e., Vulnerability)", ylab="Coefficient", labels=FALSE)
title(main="Linear Cycle Trend")

axis(1, at=1, labels="<10", tick=TRUE, las=1)
axis(1, at=2, labels="<15", tick=TRUE, las=1)
axis(1, at=3, labels="<20", tick=TRUE, las=1)
axis(1, at=4, labels="<25", tick=TRUE, las=1)
axis(1, at=5, labels="<30", tick=TRUE, las=1)
axis(1, at=6, labels="<35", tick=TRUE, las=1)
axis(1, at=7, labels="<40", tick=TRUE, las=1)
axis(1, at=8, labels="<45", tick=TRUE, las=1)
axis(1, at=9, labels="<50", tick=TRUE, las=1)
axis(1, at=10, labels=">50", tick=TRUE, las=1)

axis(2, at=-0.000004, labels="-4.0e-06", tick=TRUE, las=0)
axis(2, at=-0.000008, labels="-8.0e-06", tick=TRUE, las=0)
axis(2, at=-0.000012, labels="-1.2e-05", tick=TRUE, las=0)

segments(1, -1, 1, .5, lwd=.6, col="gray90")
segments(2, -1, 2, .5, lwd=.6, col="gray90")
segments(3, -1, 3, .5, lwd=.6, col="gray90")
segments(4, -1, 4, .5, lwd=.6, col="gray90")
segments(5, -1, 5, .5, lwd=.6, col="gray90")
segments(6, -1, 6, .5, lwd=.6, col="gray90")
segments(7, -1, 7, .5, lwd=.6, col="gray90")
segments(8, -1, 8, .5, lwd=.6, col="gray90")
segments(9, -1, 9, -0.000004, lwd=.6, col="gray90")
segments(10, -1, 10, -0.000004, lwd=.6, col="gray90")

segments(0, -0.000004, 11, -0.000004, col="gray90", lwd=.6)
segments(0, -0.000006, 11, -0.000006, col="gray90", lwd=.6)
segments(0, -0.000008, 11, -0.000008, col="gray90", lwd=.6)
segments(0, -0.00001, 11, -0.00001, col="gray90", lwd=.6)
segments(0, -0.000012, 11, -0.000012, col="gray90", lwd=.6)
segments(0, -0.000014, 11, -0.000014, col="gray90", lwd=.6)

points(counter, coef, pch=1)
#points(1, -3.365e-06, pch=19)
#points(2, -6.779e-06, pch=19)
points(3, -7.443e-06, pch=19)
points(4, -8.772e-06, pch=19)
points(5, -9.577e-06, pch=19)
points(6, -.00001098, pch=19)
points(7, -.0000118, pch=19)
points(8, -.00001226, pch=19)
points(9, -.00001208, pch=19)
points(10, -.0000131, pch=19)

lo <- loess(coef ~ counter, data=data, span = 0.5, degree = 1)
lo.x <- seq(min(data$counter), max(data$counter), length.out = 50)
lo.y <- predict(lo, lo.x)
lines(lo.x, lo.y, col="gray70", lty=5)

box() 

legend("topright", cex=.98, legend=c('~Significant', 'Significant'), pch=c(1, 19), col=c("black", "black"))

dev.off()



#Figure 4b

library(foreign)
library(readstata13)
data<-read.dta13("Figure4bData.dta")
counter<-data[,1]
coef<-data[,3]
pdf(file="Figure4b.pdf", family="Bookman")
plot(counter, coef, pch=1, xlim=c(1,10), ylim=c(-0.0002, 0.00025), xlab="Percentile Restrictions (i.e., Vulnerability)", ylab="Coefficient", labels=FALSE)
title(main="Post-1994 Election Indicator")

axis(1, at=1, labels="<10", tick=TRUE, las=1)
axis(1, at=2, labels="<15", tick=TRUE, las=1)
axis(1, at=3, labels="<20", tick=TRUE, las=1)
axis(1, at=4, labels="<25", tick=TRUE, las=1)
axis(1, at=5, labels="<30", tick=TRUE, las=1)
axis(1, at=6, labels="<35", tick=TRUE, las=1)
axis(1, at=7, labels="<40", tick=TRUE, las=1)
axis(1, at=8, labels="<45", tick=TRUE, las=1)
axis(1, at=9, labels="<50", tick=TRUE, las=1)
axis(1, at=10, labels=">50", tick=TRUE, las=1)

axis(2, at=-0.0002, labels="-2.0e-04", tick=TRUE, las=0)
axis(2, at=-0.0001, labels="-1.0e-04", tick=TRUE, las=0)
axis(2, at=0, labels="0.0e+00", tick=TRUE, las=0)
axis(2, at=0.0001, labels="1.0e-04", tick=TRUE, las=0)
axis(2, at=0.0002, labels="2.0e-04", tick=TRUE, las=0)

segments(1, -1, 1, .5, lwd=.6, col="gray90")
segments(2, -1, 2, .5, lwd=.6, col="gray90")
segments(3, -1, 3, .5, lwd=.6, col="gray90")
segments(4, -1, 4, .5, lwd=.6, col="gray90")
segments(5, -1, 5, .5, lwd=.6, col="gray90")
segments(6, -1, 6, .5, lwd=.6, col="gray90")
segments(7, -1, 7, .5, lwd=.6, col="gray90")
segments(8, -1, 8, .5, lwd=.6, col="gray90")
segments(9, -1, 9, 0.000212, lwd=.6, col="gray90")
segments(10, -1, 10, 0.000212, lwd=.6, col="gray90")

segments(0, -0.0002, 11, -0.0002, col="gray90", lwd=.6)
segments(0, -0.0001, 11, -0.0001, col="gray90", lwd=.6)
segments(0, 0, 11, 0, col="gray90", lwd=.6)
segments(0, 0.0001, 11, 0.0001, col="gray90", lwd=.6)
segments(0, 0.0002, 11, 0.0002, col="gray90", lwd=.6)

points(counter, coef, pch=1)
points(1, .00023714, pch=19)
points(2, .00018044, pch=19)
points(10, -.00018765, pch=19)

lo <- loess(coef ~ counter, data=data, span = 0.5, degree = 1)
lo.x <- seq(min(data$counter), max(data$counter), length.out = 50)
lo.y <- predict(lo, lo.x)
lines(lo.x, lo.y, col="gray70", lty=5)

box() 

legend("topright", cex=.98, legend=c('~Significant', 'Significant'), pch=c(1, 19), col=c("black", "black"))

dev.off()